using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using NazSoft.Framework;
using System.Linq;
using System.Data.Linq;
using System.Data.Linq.Mapping;
using System.Transactions;
using BCL;
using BCL.Entity.Entity;
using System.Web.UI.WebControls;

namespace BCL.Entity.Generic.DAL
{
    public partial class Result_TypeGenericDAL
    {

        #region Constructor
        public Result_TypeGenericDAL()
        { }
        #endregion

        #region Public Methods
        public List<Result_Type> Select(Result_Type Result_type, bool isCacheData = true)
        {
            string strKey = "Select" + Result_type.RType + Result_type.Datestamp + Result_type.Title + Result_type.IsActive + Result_type.ResultAnnocementDate + Result_type.ResultYear + Result_type.ResultLevel + Result_type.To + Result_type.From + (Result_type.SortingDirection == SortDirection.Descending ? "D" : "A") + Result_type.SortingField;


            List<Result_Type> data = null;


            if (isCacheData)
            {


                data = CacheHelper.Get<List<Result_Type>>(strKey);


                if (data != null) return data;
            }


            SqlHelper helper = new SqlHelper();


            object[] objName = { "RType", "Datestamp", "Title", "IsActive", "ResultAnnocementDate", "ResultYear", "ResultLevel", "To", "From", "SortDirection", "SortColumn" };
            object[] objValue = { Result_type.RType, Result_type.Datestamp, Result_type.Title, Result_type.IsActive, Result_type.ResultAnnocementDate, Result_type.ResultYear, Result_type.ResultLevel, Result_type.To, Result_type.From, Result_type.SortingDirection == SortDirection.Descending ? "D" : "A", Result_type.SortingField };
            DataTable dataTable = helper.GetDataTable("Result_Type_Select", objName, objValue);
            data = CollectionHelper.ConvertTo<Result_Type>(dataTable).ToList();
            if (isCacheData)
                CacheHelper.Add<List<Result_Type>>(data, strKey);
            return data;
        }

        public List<Result_Type> SelectWithOutPaging(Result_Type Result_type, bool isCacheData = true)
        {
            string strKey = "SelectWithOutPaging" + Result_type.RType + Result_type.Datestamp + Result_type.Title + Result_type.IsActive + Result_type.ResultAnnocementDate + Result_type.ResultYear + Result_type.ResultLevel + (Result_type.SortingDirection == SortDirection.Descending ? "D" : "A") + Result_type.SortingField;


            List<Result_Type> data = null;


            if (isCacheData)
            {


                data = CacheHelper.Get<List<Result_Type>>(strKey);


                if (data != null) return data;
            }


            SqlHelper helper = new SqlHelper();


            object[] objName = { "RType", "Datestamp", "Title", "IsActive", "ResultAnnocementDate", "ResultYear", "ResultLevel", "SortDirection", "SortColumn" };
            object[] objValue = { Result_type.RType, Result_type.Datestamp, Result_type.Title, Result_type.IsActive, Result_type.ResultAnnocementDate, Result_type.ResultYear, Result_type.ResultLevel, Result_type.SortingDirection == SortDirection.Descending ? "D" : "A", Result_type.SortingField };
            DataTable dataTable = helper.GetDataTable("Result_Type_SelectWithOutPaging", objName, objValue);
            data = CollectionHelper.ConvertTo<Result_Type>(dataTable).ToList();
            if (isCacheData)
                CacheHelper.Add<List<Result_Type>>(data, strKey);
            return data;
        }

        public Result_Type Get(Result_Type Result_type)
        {
            SqlHelper helper = new SqlHelper();


            object[] objName = { "RType", };
            object[] objValue = { Result_type.RType };
            DataTable dataTable = helper.GetDataTable("Result_Type_Get", objName, objValue);
            return CollectionHelper.ConvertTo<Result_Type>(dataTable).FirstOrDefault();
        }

        public int Save(Result_Type Result_type, string userName)
        {
            SqlHelper helper = new SqlHelper();
            int id = 0;

            Result_type.CreatedBy = userName;

            Result_type.CreatedDate = DateTime.Now;

            Result_type.UpdatedBy = userName;

            Result_type.UpdatedDate = DateTime.Now;

            using (TransactionScope t = new TransactionScope(TransactionScopeOption.Suppress))
            {

                if (Result_type.RType == 0 || Result_type.RType == null)


                    id = helper.OperationEntity("Result_Type_Insert", Result_type, OperationMode.Add, "RType");
                else

                    id = helper.OperationEntity("Result_Type_Update", Result_type, OperationMode.Edit, "");
                t.Complete();

            }

            CacheHelper.ClearAll();

            return id;
        }

        public int DeleteSoft(Result_Type Result_type)
        {
            SqlHelper helper = new SqlHelper();
            int id = 0;

            Result_type.CreatedBy = SessionHandler.UserInfo.Username;

            Result_type.CreatedDate = DateTime.Now;

            Result_type.UpdatedBy = SessionHandler.UserInfo.Username;

            Result_type.UpdatedDate = DateTime.Now;

            using (TransactionScope t = new TransactionScope(TransactionScopeOption.Suppress))
            {
                id = helper.OperationEntity("Result_Type_DeleteSoft", Result_type, OperationMode.Delete, "");
                t.Complete();

            }

            CacheHelper.ClearAll();

            return id;
        }

        public int Delete(Result_Type Result_type)
        {
            SqlHelper helper = new SqlHelper();
            int id = 0;

            Result_type.CreatedBy = SessionHandler.UserInfo.Username;

            Result_type.CreatedDate = DateTime.Now;

            Result_type.UpdatedBy = SessionHandler.UserInfo.Username;

            Result_type.UpdatedDate = DateTime.Now;

            using (TransactionScope t = new TransactionScope(TransactionScopeOption.Suppress))
            {
                id = helper.OperationEntity("Result_Type_Delete", Result_type, OperationMode.Delete, "");
                t.Complete();

            }

            CacheHelper.ClearAll();

            return id;
        }

        #endregion

    }
}
